//
//  BaseBackgroundView.swift
//  SmartHousekeeper
//
//  Created by 张磊 on 2020/2/20.
//  Copyright © 2020 LS. All rights reserved.
//

import UIKit



class BaseBackgroundView: UIView {
    func remarkSnpBaseView(){
        backView.snp.remakeConstraints { (make) in
            make.top.equalTo(backBtn.snp_bottomMargin).offset(Adapter(15))
            make.left.equalToSuperview().offset(Adapter(15))
            make.right.equalToSuperview().offset(Adapter(-15))
            make.bottom.equalToSuperview().offset(Adapter(-120))
        }
        company.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(backView.snp.bottom).offset(Adapter(30))
            make.height.equalTo(Adapter(15))
        }
    }
    typealias BaseBackgroundViewBackBlock = ()->()
    public var backBlock:BaseBackgroundViewBackBlock? = nil
    
    let backGroudImg = UIImageView()
    let backBtn = UIButton()
    let backView = UIView()
    let company = UILabel()
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUi()
    }
    private func setUi(){
        let top = UIDevice.isX() ? 44 : 20;
        
        backGroudImg.image = UIImage(named: "mianBack")
        self .addSubview(backGroudImg)
        backGroudImg.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        backBtn.setTitle("返回", for: .normal)
        backBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15);
        backBtn.setImage(UIImage(named: "back"), for: .normal)
        backBtn.setTitleColor(.white, for: .normal)
        backBtn.addTarget(self, action: #selector(backAction), for: .touchUpInside)
        self.addSubview(backBtn)
        backBtn.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(top)
            make.left.equalToSuperview()
            make.size.equalTo(CGSize(width: 80, height: 44))
        }
        self.layoutIfNeeded()
        backBtn.imagePosition(at: .left, space: 5)
        
        
        backView.backgroundColor = .white
        backView.layer.cornerRadius = 8
        backView.layer.masksToBounds = true
        self.addSubview(backView)
        backView.snp.makeConstraints { (make) in
            make.top.equalTo(backBtn.snp_bottomMargin).offset(Adapter(15))
            make.left.equalToSuperview().offset(Adapter(15))
            make.right.equalToSuperview().offset(Adapter(-15))
            make.bottom.equalToSuperview().offset(Adapter(-60))
        }
        
        company.textColor = RGBColor(r: 116, g: 116, b: 116, a: 1)
        company.font = UIFont.systemFont(ofSize: Adapter(12))
        company.text = "技术提供商:上海领美软件科技有限公司"
        self.addSubview(company)
        company.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(Adapter(-30))
            make.height.equalTo(Adapter(15))
        }
        
        
    }
    @objc private func backAction(){
        if backBlock != nil {
            backBlock!()
        }
        
    }
    
}
